from core.basehandler import BaseHandler
from core.room import Room
from items.meter import ConfidenceMeter
from core.action import Action
from core.support import set_cutscene
from core.support import get_game

class Cornwalls(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
    
        # add inventory items
        self.add_item(ConfidenceMeter())
        
        # build list of actions
        self.add_action(GoToBar)
        self.add_action(GoPlayPool)
        self.add_action(TalkToMC)
        #self.game = get_game() 
        #self.player = self.game.get_player()
        #self.player.pop_item('Pointer()')
        
    # return description of room.
    def get_description(self):
        return "You walk into Corn Walls, but everything is weird. You checks your 'forces meter' and it is set to Dilemma - the highest setting. There are pool tables on your right and the bar in front of you. Your arch-nemesis, Michael Christenson is sitting at one of the tables-- you think he stole your MBA, and you feel that you need to talk to him."
    
    # return image of room
    def get_image(self):
        return 'cornwallsBro.jpg'
  

class CornwallsHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Cornwalls
    
    def get_template(self):
        player = self.game.get_player()
        if player.beers_count == 5:
            return 'room2.html'
        else:
            return 'room.html'
        
# define actions for this room

class GoToBar(Action):
    def __init__(self):
        Action.__init__(self, "GoToBar")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go To Bar"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'bar'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
class GoPlayPool(Action):
    def __init__(self):
        Action.__init__(self, "GoPlayPool")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go Play Pool"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'pool'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"    

class TalkToMC(Action):
    def __init__(self):
        Action.__init__(self, "TalkToMC")    # do basic initialization for every action
    
        # return description of action (used in label on webpage)
    def get_description(self):
        return "Talk to MC"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        g = get_game()
        p = g.get_player()
        if p.confidence < 10:
            return 'cornwalls'
        else:
            return 'nacho_contest'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    def do_action(self,game,room,request):
        p = game.get_player()
        if p.confidence < 10:
            set_cutscene("You need to build up your confidence to atleast Level 10 before you can talk to MC. Try Drinking beers or playing pool.")
        return